<template>
  <el-dialog title="设置检录类型" class="gl_dialog_TitleLine" :visible.sync="dialogVisible" width="660px">
    <div>
      <span class="gl_pr_15">检录类型</span>
      <el-select v-model="SiSTKWEventsManagementUpdateSetCompetitionClerkInType.checkInCode" size="mini" placeholder="请选择" clearable filterable>
        <el-option v-for="(item, index) in checkType" :key="index" :label="item.value" :value="item.code" />
      </el-select>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" size="mini" @click="save()">保 存</el-button>
      <el-button size="mini" @click="dialogVisible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import {
  api_PUT_EventsManagementClerkOfCourseSetCompetitionClerkInType // 批量设置赛事检录人员的检录类型
} from '@/extend/api/gameswaggerApi/app.js';
import {
  SiSTKWEventsManagementUpdateSetCompetitionClerkInType
} from '@/lib/form/game/swaggerForm';
export default {
  name: 'CheckType',
  props: {
    selection: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      dialogVisible: false,
      SiSTKWEventsManagementUpdateSetCompetitionClerkInType: new SiSTKWEventsManagementUpdateSetCompetitionClerkInType(),
      checkType: []
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict
    })
  },
  created() {
    this.getDict().then(res => {
      this.checkType = res.checkInType.filter((item) => {
        return item.code !== 'NotSet';
      });
    });
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict' }),
    open() {
      this.dialogVisible = true;
    },
    // 保存
    save() {
      var that = this;
      var form = that.SiSTKWEventsManagementUpdateSetCompetitionClerkInType;
      if (form.checkInCode !== '') {
        that.loading = true;
        form.competitionId = this.$route.params.id;
        form.clerkOfCourseRepositoryIds = this.selection;
        api_PUT_EventsManagementClerkOfCourseSetCompetitionClerkInType(form).then(res => {
          that.loading = false;
          that.dialogVisible = false;
          that.$message({
            type: 'success',
            message: '设置成功!'
          });
          that.SiSTKWEventsManagementUpdateSetCompetitionClerkInType = new SiSTKWEventsManagementUpdateSetCompetitionClerkInType();
          that.$parent.getCheckPeople();
        }).catch(() => {
          that.loading = false;
          that.dialogVisible = false;
          that.SiSTKWEventsManagementUpdateSetCompetitionClerkInType = new SiSTKWEventsManagementUpdateSetCompetitionClerkInType();
          that.$message({
            type: 'error',
            message: '设置失败!'
          });
        });
      } else {
        this.$message({
          type: 'warning',
          message: '请先选择检录类型'
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>

</style>
